package com.example.demo.hadoop.reduce.model;

import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

public class GroupSortModel implements WritableComparable<GroupSortModel> {
    private int name;
    private int num;

    public GroupSortModel(int name, int num) {
        this.name = name;
        this.num = num;
    }

    public GroupSortModel() {
    }

    public void set(int name, int num) {
        this.name = name;
        this.num = num;
    }


    @Override
    public int compareTo(GroupSortModel o) {
        if (this.name != o.getName()) {
            return this.name < o.getName() ? -1 : 1;
        } else if (this.num != o.getNum()) {
            return this.num < o.getNum() ? -1 : 1;
        } else {
            return 0;
        }
    }

    @Override
    public void write(DataOutput dataOutput) throws IOException {
        dataOutput.writeInt(this.name);
        dataOutput.writeInt(this.num);
    }

    @Override
    public void readFields(DataInput dataInput) throws IOException {
        this.name = dataInput.readInt();
        this.num = dataInput.readInt();
    }

    public int getName() {
        return name;
    }

    public void setName(int name) {
        this.name = name;
    }

    public int getNum() {
        return num;
    }

    public void setNum(int num) {
        this.num = num;
    }
}
